<?php  
include 'codeBack.config.php';
include "connectMysql.php";
include "empty.php";
include 'header.php';
$user_id = $_POST["user_id"];
$user_name = $_POST["user_name"];
$diary = $_POST["diary"];
$token = $_POST["token"];
if(!$user_id || !$user_name || !$diary || !$token){
	exit();
}

$ac_user_sql = "SELECT * FROM ac_user WHERE user_id='$user_id' AND token='$token'";
$ac_user_result = $mysqli->query($ac_user_sql);
$ac_user_row = mysqli_fetch_object($ac_user_result);
if($ac_user_row->token == $token && $ac_user_row->user_id == $user_id){
	// 查找成功
	$ac_user_info_sql = "INSERT INTO ac_user_diary (user_name,diary,user_id) VALUES('$user_name','$diary','$userid')";
	$ac_user_info_result = $mysqli->query($ac_user_info_sql);
	if($ac_user_info_result){
		// 大于 0 表示插入成功
		// 插入成功
		$data = [
			"code"=>$CodeBack["DIARY_SUCCESS_CODE"],
			"user_id"=>$user_id,
			"id"=>$mysqli->insert_id,
			"message"=>"保存成功",
		];
		echo json_encode($data);
	}else {
		$data = [
			"code"=>$CodeBack["DIARY_FAILED_CODE"],
			"message"=>"保存失败，请稍候重试",
		];
		echo json_encode($data);
	}
}
